<?php
namespace Home\Controller;
use Think\Controller;

class BaseController extends Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->_init();
    }

    public function _init()
    {
        $nav_flag = I('get.nav_flag', 'index', 'trim');
        $this->assign('nav_flag', $nav_flag);
    }

    protected function getNewsCatList()
    {
        return M('NewsCategory')->order('sort asc')->select();
    }

    public function getCatList($cat1_id)
    {
        $mdlCategory = M('SinglePageCategory');
        $condition = array(
            'parent_id' => (int)$cat1_id,
        );
        $cat_list = $mdlCategory->where($condition)->select();
        foreach($cat_list as $key => $item) {
            $sub_cat_list = array();
            $resList = $mdlCategory->where(array('parent_id' => $item['id']))->select();
            foreach ($resList as  $subItem) {
                $sub_cat_list[$subItem['id']] = $subItem;
            }
            $cat_list[$key]['sub_cat_list'] = $sub_cat_list;
        }
        return $cat_list;
    }
}